package com.wiloon.java8x.design.pattern.singleton;

class SingletonMain {

	static Singleton instance;

	public static Singleton getInstance() {
		if (instance == null) {
			synchronized (SingletonMain.class) {
				if (instance == null)
					instance = new Singleton();
			}
		}
		return instance;
	}
}

class R implements Runnable {
	public void run() {
		System.out.println(SingletonMain.getInstance().toString());
	}
}

public class Singleton {
	public static void main(String[] args) {

		R r = new R();
		for (int i = 0; i <= 50; i++) {
			Thread t = new Thread(r);
			t.start();
		}
		// System.out.println(SingletonMain.getInstance() ==
		// SingletonMain.getInstance());
	}
}